package com.itheima05;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.net.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UDP03 {
    public static void main(String[] args) throws IOException {

        DatagramSocket datagramSocket = new DatagramSocket();

        InetAddress byName = InetAddress.getByName("127.0.0.1");

        new Thread(() -> {


            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            while (true) {

                Date a = new Date();
                String format = sdf.format(a);

                byte[] bytes = format.getBytes();
                DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, byName, 10000);

                try {
                    datagramSocket.send(datagramPacket);
                    Thread.sleep(1000);
                } catch (IOException | InterruptedException e) {
                    e.printStackTrace();
                }

            }

        }).start();
    }
}
